<?php
  //冒泡排序法
  $v = [14,5,21,8,56];
  echo "<br>交换前".implode('-',$v);
  $len = count($v);
  for($i =0;$i<$len-1;$i++){
      for($j = 0;$j<$len-1-$i;$j++){
          if($v[$j]>$v[$j+1]){
             $temp = $v[$j];
             $v[$j] = $v[$j+1];
             $v[$j+1] = $temp;
          }
      }
  }
  echo "<br>交换后".implode('-',$v);

  echo "<hr>";

  //选择排序法
  $arr = [1,34,35,2,76,23];
  echo "<br>交换前".implode('-', $arr);
  $length = count($arr);
  
  for($i = 0;$i<$length-1;$i++){
    $max = $arr[0];
    $max_k = 0;
      for($j = 0;$j<$length-$i;$j++){
          if($max<$arr[$j]){
              $max = $arr[$j];
              $max_k = $j;
          }
      }
      $temp = $arr[$max_k];
      $arr[$max_k] = $arr[$length-$i-1];
      $arr[$length-$i-1] = $temp;

  }
  echo "<br>交换后".implode('-', $arr);
?>